﻿[Output_None]
	[var:'new_lang_id'=(encode_sql:(action_param:'tree_langid'))]
	[var:'new_page_parent_id'=(encode_sql:(action_param:'tree_currentpageid'))]
	[var:'new_page_type_param'=(encode_sql:(action_param:'tree_pagetype'))]
	
	[if:($new_page_type_param)=='Page']
		[var:'new_page_type'=1]
		[var:'new_page_type_txt'='Page']
	[else]
		[var:'new_page_type'=2]
		[var:'new_page_type_txt'='URL']
	[/if]
	

	[var:'sql_add_page'='
		INSERT INTO		SHb_pages
		SET				_r_cre_account	= \'website\',
						_r_mod_account	= \'website\' ']
	
	[Inline: -database='SHoebox', -sql=$sql_add_page]
		[if:(error_currenterror:-errorcode)==0]
			[var:'sql_get_last_page'='SELECT LAST_INSERT_ID()']
			[Inline: -database='SHoebox', -sql=$sql_get_last_page]
				[var:'new_page_id'=(field:'last_insert_id()')]
			[/inline]
		[/if]
	[/inline]
		
		
		
	<!-- parentid opzoeken om menuid te krijgen -->
	[var:'sql_search_parent_menuid'='
		SELECT	*
		FROM	SHb_menus
		WHERE	_k2_pageid	= ' + $new_page_parent_id ]
	
	[Inline: -database='SHoebox', -sql=$sql_search_parent_menuid]
		[if:(error_currenterror:-errorcode)==0]
			[var:'new_parent_id'=(field:'_k1_menuid')]
		[/if]
	[/inline]	
		
	
	[var:'sql_add_menus'='
		INSERT INTO		SHb_menus
		SET				_r_cre_account	= \'website\',
						_r_mod_account	= \'website\',
						_k2_pagetypeid	= ' + $new_page_type + ',
						active 			= 1,
						target_window	= \'_self\',
						_k2_levelid		= \'\',
						_k2_parentid	= ' + $new_parent_id + ',
						_k2_pageid		= ' + $new_page_id + ',
						target_url		= \'\' ']
		

	[Inline: -database='SHoebox', -sql=$sql_add_menus]
		[if:(error_currenterror:-errorcode)==0]
		
			[var:'sql_get_last_menu'='SELECT LAST_INSERT_ID()']
			[Inline: -database='SHoebox', -sql=$sql_get_last_menu]
				[var:'new_menu_id'=(field:'last_insert_id()')]
			[/inline]
			
			
			[var:'sql_add_pages_translations'='
				INSERT INTO		SHb_translations_pages
				SET				_k2_pageid = ' + $new_page_id + ',
								_k2_languageid = ' + $new_lang_id + ',
								_r_cre_account = \'website\',
								_r_mod_account = \'website\',
								page_title = \'Untitled\'
			']
			[Inline: -database='SHoebox', -sql=$sql_add_pages_translations][/inline]
			
			
			[var:'sql_add_menus_translations'='
				INSERT INTO		SHb_translations_menus
				SET				_k2_menuid = ' + $new_menu_id + ',
								_k2_languageid = ' + $new_lang_id + ',
								_r_cre_account = \'website\',
								_r_mod_account = \'website\',
								label = \'Untitled\'
			']
			[Inline: -database='SHoebox', -sql=$sql_add_menus_translations]
				[if:(error_currenterror:-errorcode)==0]
				[var:'output_message'='An error occured while saving1']
					[var:'output_message'=$new_page_id]
				[else]
					[var:'output_message'='<b>An error occured while adding the ' + $new_page_type_txt + '</b>']
				[/if]
			[/inline]
			
				
		[else]
			
			[var:'output_message'='<b>An error occured while adding the ' + $new_page_type_txt + '</b>']
					
		[/if]
	[/inline]
[/Output_None]
[var:'output_message',-encodenone]